class Page4 extends egret.DisplayObjectContainer{
	private bmp_bg:egret.Bitmap;
	private bmp_t0:egret.Bitmap;
	private bmp_t1:egret.Bitmap;
	private bmp_t2:egret.Bitmap;
	private bmp_t3:egret.Bitmap;
	private bmp_2017:egret.Bitmap;
	private bmp_tip1:egret.Bitmap;
	private bmp_tip2:egret.Bitmap;
	private mc:egret.MovieClip;
	private particle:particle.GravityParticleSystem;
	private sd_effect:egret.Sound;
	// private sc_effect:egret.SoundChannel;
	public constructor() {
		super();

		this.sd_effect=RES.getRes('effect1_mp3');

		this.bmp_bg=new egret.Bitmap();
		this.bmp_bg.texture=RES.getRes('p4_bg_png');
		// this.bmp_bg.anchorOffsetX=this.bmp_bg.width/2;
		// this.bmp_bg.anchorOffsetY=this.bmp_bg.height/2;
		this.bmp_bg.x=0;
		this.bmp_bg.y=0;
		this.addChild(this.bmp_bg);

		this.bmp_t0=new egret.Bitmap();
		this.bmp_t0.texture=RES.getRes('p4_title0_png');
		this.bmp_t0.anchorOffsetX=this.bmp_t0.width/2;
		this.bmp_t0.anchorOffsetY=this.bmp_t0.height/2;
		this.bmp_t0.x=194;
		this.bmp_t0.y=177;
		this.bmp_t0.alpha=0;
		

		this.bmp_t1=new egret.Bitmap();
		this.bmp_t1.texture=RES.getRes('p4_title1_png');
		this.bmp_t1.anchorOffsetX=this.bmp_t1.width/2;
		this.bmp_t1.anchorOffsetY=this.bmp_t1.height/2;
		this.bmp_t1.x=375;
		this.bmp_t1.y=740;
		this.bmp_t1.alpha=0;
		this.addChild(this.bmp_t1);

		this.bmp_t2=new egret.Bitmap();
		this.bmp_t2.texture=RES.getRes('p4_title2_png');
		this.bmp_t2.anchorOffsetX=this.bmp_t2.width/2;
		this.bmp_t2.anchorOffsetY=this.bmp_t2.height/2;
		this.bmp_t2.x=376;
		this.bmp_t2.y=855;
		this.bmp_t2.alpha=0;
		this.addChild(this.bmp_t2);

		this.bmp_t3=new egret.Bitmap();
		this.bmp_t3.texture=RES.getRes('p4_title3_png');
		this.bmp_t3.anchorOffsetX=this.bmp_t3.width/2;
		this.bmp_t3.anchorOffsetY=this.bmp_t3.height/2;
		this.bmp_t3.x=371;
		this.bmp_t3.y=947;
		this.bmp_t3.alpha=0;
		this.addChild(this.bmp_t3);

		this.particle = new particle.GravityParticleSystem(RES.getRes("leaf_png"), RES.getRes("leaf_json"));
		// this.particle.start();
		this.addChild(this.particle);
		console.log(this.particle);

		this.bmp_tip1=new egret.Bitmap();
		this.bmp_tip1.texture=RES.getRes('p1_tip1_png');
		this.bmp_tip1.anchorOffsetX=this.bmp_tip1.width/2;
		this.bmp_tip1.anchorOffsetY=this.bmp_tip1.height/2;
		this.bmp_tip1.x=370;
		this.bmp_tip1.y=1080;
		this.bmp_tip1.alpha=0.5;
		this.addChild(this.bmp_tip1);
		egret.Tween.get(this.bmp_tip1,{loop:true}).to({y:1110,alpha:1},600,egret.Ease.cubicInOut).to({y:1080,alpha:0.5},600,egret.Ease.cubicInOut);

		this.bmp_tip2=new egret.Bitmap();
		this.bmp_tip2.texture=RES.getRes('p1_tip2_png');
		this.bmp_tip2.anchorOffsetX=this.bmp_tip2.width/2;
		this.bmp_tip2.anchorOffsetY=this.bmp_tip2.height/2;
		this.bmp_tip2.x=356;
		this.bmp_tip2.y=1120;
		this.bmp_tip2.alpha=0;
		// this.addChild(this.bmp_tip2);
		// egret.Tween.get(this.bmp_tip2).to({y:1103,alpha:0.5},600,egret.Ease.cubicInOut).to({y:1120,alpha:1},600,egret.Ease.cubicInOut);

		this.mc = new egret.MovieClip( MovieClipData.mcFactory4.generateMovieClipData( "mc4" ));
		this.mc.frameRate=12;
		this.addChild(this.mc);
		this.mc.x=60;
		this.mc.y=0;
		this.mc.visible=false
		this.mc.alpha=1;
		// this.mc3.gotoAndPlay(1,1)
		// this.mc3.addEventListener(egret.Event.COMPLETE,this.loopHandler,this);
		this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
		// this.mc.addEventListener(egret.Event.COMPLETE,this.loopHandler,this);
		this.addChild(this.bmp_t0);
	}

	// private loopHandler(e:egret.Event):void
	// {
	// 	this.mc.frameRate=5;
	// 	this.mc.gotoAndPlay(24,1)
	// }
	private addToStage(e:egret.Event):void
	{
		// this.bmp_t0.scaleX=this.bmp_t1.scaleY=0;
		
		
	}

	private t1:number;
	private t2:number;
	public In():void
	{
		// this.sc_effect=this.sd_effect.play(0,1);

		this.removeTween();
		if(this.t1)
		{
			clearTimeout(this.t1);
		}
		if(this.t2)
		{
			clearTimeout(this.t2)
		}
		if(this.particle.visible)
		{
			this.particle.visible=false;
		}

		this.bmp_t0.y=177-50;
		this.bmp_t0.alpha=0;
		egret.Tween.get(this.bmp_t0).wait(1000).to({y:177,alpha:1},1000,egret.Ease.cubicInOut);

		this.bmp_t1.y=739+30;
		this.bmp_t1.alpha=0;
		egret.Tween.get(this.bmp_t1).wait(1000+700).to({y:739,alpha:1},1000,egret.Ease.cubicInOut);

		this.bmp_t2.scaleX=this.bmp_t2.scaleY=1;
		this.bmp_t2.alpha=0;
		this.bmp_t2.y=854+30;
		egret.Tween.get(this.bmp_t2).wait(1000+1400).to({y:854,scaleX:1,scaleY:1,alpha:1},1000,egret.Ease.cubicInOut);

		this.bmp_t3.y=947+30;
		this.bmp_t3.alpha=0;
		egret.Tween.get(this.bmp_t3).wait(1000+2100).to({y:947,alpha:1},1000,egret.Ease.cubicInOut);

		var myThis=this;
		this.t1=setTimeout(function() {
			// myThis.particle.stop();
		},2000);


		this.mc.visible=false;
		this.mc.alpha=1;
		// this.mc.frameRate=12;
		this.t2=setTimeout(function() {
			myThis.particle.start();
			myThis.particle.visible=true;
			myThis.mc.visible=true;
			myThis.mc.gotoAndPlay(1);
		}, (0));
	}
	
	private twAll;
    public Out():void
	{
		// if(this.sc_effect)
		// {
		// 	this.sc_effect.stop();
		// 	this.sc_effect=null;
		// }
		this.removeTween();
		this.particle.stop();
		if(this.t1)
		{
			clearTimeout(this.t1);
		}
		if(this.t2)
		{
			clearTimeout(this.t2)
		}
		egret.Tween.get(this.bmp_t0).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t1).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t2).to({ alpha: 0 }, 400);
		egret.Tween.get(this.bmp_t3).to({ alpha: 0 }, 400);
		egret.Tween.get(this.mc).to({ alpha: 0 }, 400);
	}
	private removeTween():void
	{
		egret.Tween.removeTweens(this.bmp_t0);
		egret.Tween.removeTweens(this.bmp_t1);
		egret.Tween.removeTweens(this.bmp_t2);
		egret.Tween.removeTweens(this.bmp_t3);
		egret.Tween.removeTweens(this.mc);
	}
}